{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:53.983187Z",
     "start_time": "2021-11-13T07:29:53.525412Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.155424Z",
     "start_time": "2021-11-13T07:29:54.045885Z"
    }
   },
   "outputs": [],
   "source": [
    "SalesData = pd.read_excel('data/国家销售情况.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.171283Z",
     "start_time": "2021-11-13T07:29:54.156320Z"
    }
   },
   "outputs": [],
   "source": [
    "# 将日期改为年份/季度，并且增加年份和季度字段\n",
    "# 将日期转换为时间类型\n",
    "SalesData['日期'] = pd.to_datetime(SalesData['日期'])\n",
    "\n",
    "# 1、增加年份字段\n",
    "SalesData['年份'] = (SalesData['日期'].dt.year).apply(str)\n",
    "\n",
    "# 增加季度字段\n",
    "SalesData['季度'] = (SalesData['日期'].dt.quarter).apply(str)\n",
    "\n",
    "SalesData['年份/季度'] = SalesData['年份'].str.cat(SalesData['季度'],sep='/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.202225Z",
     "start_time": "2021-11-13T07:29:54.172277Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>国家</th>\n",
       "      <th>城市</th>\n",
       "      <th>地区</th>\n",
       "      <th>服务分类</th>\n",
       "      <th>销售额</th>\n",
       "      <th>利润</th>\n",
       "      <th>年份</th>\n",
       "      <th>季度</th>\n",
       "      <th>年份/季度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Cote d'Ivoire</td>\n",
       "      <td>Abidjan</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>656.96</td>\n",
       "      <td>6.57</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Madagascar</td>\n",
       "      <td>Antananarivo</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>875.94</td>\n",
       "      <td>-70.08</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Rwanda</td>\n",
       "      <td>Kigali</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>258.35</td>\n",
       "      <td>18.08</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Zimbabwe</td>\n",
       "      <td>Harare</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>875.62</td>\n",
       "      <td>-35.02</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-01-02</td>\n",
       "      <td>Ethiopia</td>\n",
       "      <td>Addis Ababa</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>509.93</td>\n",
       "      <td>10.20</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          日期             国家            城市       地区         服务分类     销售额  \\\n",
       "0 2017-01-01  Cote d'Ivoire       Abidjan  Western   Commercial  656.96   \n",
       "1 2017-01-01     Madagascar  Antananarivo  Eastern       Public  875.94   \n",
       "2 2017-01-01         Rwanda        Kigali  Eastern       Public  258.35   \n",
       "3 2017-01-01       Zimbabwe        Harare  Eastern  Residential  875.62   \n",
       "4 2017-01-02       Ethiopia   Addis Ababa  Eastern  Residential  509.93   \n",
       "\n",
       "      利润    年份 季度   年份/季度  \n",
       "0   6.57  2017  1  2017/1  \n",
       "1 -70.08  2017  1  2017/1  \n",
       "2  18.08  2017  1  2017/1  \n",
       "3 -35.02  2017  1  2017/1  \n",
       "4  10.20  2017  1  2017/1  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "SalesData.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.218253Z",
     "start_time": "2021-11-13T07:29:54.203195Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>国家</th>\n",
       "      <th>城市</th>\n",
       "      <th>地区</th>\n",
       "      <th>服务分类</th>\n",
       "      <th>销售额</th>\n",
       "      <th>利润</th>\n",
       "      <th>年份</th>\n",
       "      <th>季度</th>\n",
       "      <th>年份/季度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Cote d'Ivoire</td>\n",
       "      <td>Abidjan</td>\n",
       "      <td>Western</td>\n",
       "      <td>Commercial</td>\n",
       "      <td>656.96</td>\n",
       "      <td>6.57</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Madagascar</td>\n",
       "      <td>Antananarivo</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>875.94</td>\n",
       "      <td>-70.08</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Rwanda</td>\n",
       "      <td>Kigali</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Public</td>\n",
       "      <td>258.35</td>\n",
       "      <td>18.08</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01-01</td>\n",
       "      <td>Zimbabwe</td>\n",
       "      <td>Harare</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>875.62</td>\n",
       "      <td>-35.02</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-01-02</td>\n",
       "      <td>Ethiopia</td>\n",
       "      <td>Addis Ababa</td>\n",
       "      <td>Eastern</td>\n",
       "      <td>Residential</td>\n",
       "      <td>509.93</td>\n",
       "      <td>10.20</td>\n",
       "      <td>2017</td>\n",
       "      <td>1</td>\n",
       "      <td>2017/1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          日期             国家            城市       地区         服务分类     销售额  \\\n",
       "0 2017-01-01  Cote d'Ivoire       Abidjan  Western   Commercial  656.96   \n",
       "1 2017-01-01     Madagascar  Antananarivo  Eastern       Public  875.94   \n",
       "2 2017-01-01         Rwanda        Kigali  Eastern       Public  258.35   \n",
       "3 2017-01-01       Zimbabwe        Harare  Eastern  Residential  875.62   \n",
       "4 2017-01-02       Ethiopia   Addis Ababa  Eastern  Residential  509.93   \n",
       "\n",
       "      利润    年份 季度   年份/季度  \n",
       "0   6.57  2017  1  2017/1  \n",
       "1 -70.08  2017  1  2017/1  \n",
       "2  18.08  2017  1  2017/1  \n",
       "3 -35.02  2017  1  2017/1  \n",
       "4  10.20  2017  1  2017/1  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、将各个年份第1季度的各个地区，国家，服务分类的分别提取出来\n",
    "data = SalesData[SalesData['季度']=='1']\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "上表为各个国家、地区、服务分类第一季度的销售额和利润数据情况的前5项</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.233180Z",
     "start_time": "2021-11-13T07:29:54.220148Z"
    }
   },
   "outputs": [],
   "source": [
    "yearoneSaleArea_sales = data.groupby(['年份','地区']).sum()['销售额']\n",
    "yearoneSaleArea_profit = data.groupby(['年份','地区']).sum()['利润']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "上述是对数据先进行\"年份\"分类再对\"地区\"进行分类，得到<span class=\"burk\">每年关于地区的销售额和利润情况</span></div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.249165Z",
     "start_time": "2021-11-13T07:29:54.235175Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "年份    地区      \n",
       "2017  Eastern     15055.34\n",
       "      Middle       9866.53\n",
       "      Northern     4966.67\n",
       "      Southern     4183.27\n",
       "      Western     13517.47\n",
       "2018  Eastern     11856.15\n",
       "      Middle       5589.29\n",
       "      Northern     5253.70\n",
       "      Southern     8072.23\n",
       "      Western     14750.36\n",
       "2019  Eastern     13137.45\n",
       "      Middle       6973.37\n",
       "      Northern     3640.88\n",
       "      Southern     5010.49\n",
       "      Western     14826.14\n",
       "2020  Eastern     13997.27\n",
       "      Middle       7521.96\n",
       "      Northern     3839.43\n",
       "      Southern     4895.71\n",
       "      Western     15456.14\n",
       "Name: 销售额, dtype: float64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yearoneSaleArea_sales"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "上表数据是每年关于地区的<span class=\"burk\">销售额</span>情况</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.265095Z",
     "start_time": "2021-11-13T07:29:54.250134Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "年份    地区      \n",
       "2017  Eastern     -31.39\n",
       "      Middle      293.39\n",
       "      Northern    165.14\n",
       "      Southern    -62.89\n",
       "      Western     184.98\n",
       "2018  Eastern     175.83\n",
       "      Middle       -7.37\n",
       "      Northern    275.23\n",
       "      Southern    412.36\n",
       "      Western     -99.38\n",
       "2019  Eastern      45.95\n",
       "      Middle      394.69\n",
       "      Northern    101.16\n",
       "      Southern     77.29\n",
       "      Western    -135.50\n",
       "2020  Eastern     347.48\n",
       "      Middle      162.34\n",
       "      Northern   -108.14\n",
       "      Southern     58.63\n",
       "      Western     140.60\n",
       "Name: 利润, dtype: float64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yearoneSaleArea_profit"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "上表数据是每年关于地区的<span class=\"burk\">利润</span>情况</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.281052Z",
     "start_time": "2021-11-13T07:29:54.266093Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([15055.34,  9866.53,  4966.67,  4183.27, 13517.47, 11856.15,\n",
       "        5589.29,  5253.7 ,  8072.23, 14750.36, 13137.45,  6973.37,\n",
       "        3640.88,  5010.49, 14826.14, 13997.27,  7521.96,  3839.43,\n",
       "        4895.71, 15456.14])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2017-2020 [Eastern,Middle,Northern,Southern,Western]\n",
    "yearoneSaleArea_sales.values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "上表是关于2017-2020 [Eastern,Middle,Northern,Southern,Western]的销售额数据</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.297009Z",
     "start_time": "2021-11-13T07:29:54.282051Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([13997.27,  7521.96,  3839.43,  4895.71, 15456.14])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_test = yearoneSaleArea_sales.values[-5:]\n",
    "x_test"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "上表为需要预测的数据(输入2020预测2021)</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.312990Z",
     "start_time": "2021-11-13T07:29:54.298007Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([15055.34,  9866.53,  4966.67,  4183.27, 13517.47, 11856.15,\n",
       "        5589.29,  5253.7 ,  8072.23, 14750.36, 13137.45,  6973.37,\n",
       "        3640.88,  5010.49, 14826.14])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yearoneSaleArea_sales_x_train = yearoneSaleArea_sales.values[:-5]\n",
    "yearoneSaleArea_sales_x_train"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<span class=\"mark\">上表取2017-2019年的销售额数据为<span class=\"burk\">地区销售额的训练数据</span></span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:54.328238Z",
     "start_time": "2021-11-13T07:29:54.313963Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([11856.15,  5589.29,  5253.7 ,  8072.23, 14750.36, 13137.45,\n",
       "        6973.37,  3640.88,  5010.49, 14826.14, 13997.27,  7521.96,\n",
       "        3839.43,  4895.71, 15456.14])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yearoneSaleArea_sales_y_train = yearoneSaleArea_sales.values[5:]\n",
    "yearoneSaleArea_sales_y_train"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<span class=\"mark\">上表取2018-2020年的销售额数据为<span class=\"burk\">上一年地区销售额的目的标签</span></span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:55.186115Z",
     "start_time": "2021-11-13T07:29:54.329184Z"
    }
   },
   "outputs": [],
   "source": [
    "# 标准化\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "\n",
    "# 特征值标准化 \n",
    "std_x = StandardScaler()\n",
    "x_train = std_x.fit_transform(yearoneSaleArea_sales_x_train.reshape(-1,1))\n",
    "x_test = std_x.transform(x_test.reshape(-1,1))\n",
    "\n",
    "# 目标值标准化\n",
    "std_y = StandardScaler()\n",
    "y_train = std_y.fit_transform(yearoneSaleArea_sales_y_train.reshape(-1, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:55.200980Z",
     "start_time": "2021-11-13T07:29:55.188013Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据标准化之前： [[15055.34]\n",
      " [ 9866.53]\n",
      " [ 4966.67]\n",
      " [ 4183.27]\n",
      " [13517.47]\n",
      " [11856.15]\n",
      " [ 5589.29]\n",
      " [ 5253.7 ]\n",
      " [ 8072.23]\n",
      " [14750.36]\n",
      " [13137.45]\n",
      " [ 6973.37]\n",
      " [ 3640.88]\n",
      " [ 5010.49]\n",
      " [14826.14]]\n",
      "数据标准化之后： [[ 1.41461264]\n",
      " [ 0.17932256]\n",
      " [-0.98717773]\n",
      " [-1.17368027]\n",
      " [ 1.04849487]\n",
      " [ 0.65298759]\n",
      " [-0.83895178]\n",
      " [-0.91884505]\n",
      " [-0.247843  ]\n",
      " [ 1.34200663]\n",
      " [ 0.95802423]\n",
      " [-0.5094465 ]\n",
      " [-1.30280602]\n",
      " [-0.97674559]\n",
      " [ 1.36004743]]\n"
     ]
    }
   ],
   "source": [
    "print(\"数据标准化之前：\",yearoneSaleArea_sales_x_train.reshape(-1,1))\n",
    "print(\"数据标准化之后：\",x_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "对数据进行标准化过程的前后变化</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:55.280004Z",
     "start_time": "2021-11-13T07:29:55.201976Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SGDRegressor(max_iter=500)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import SGDRegressor\n",
    "sgd = SGDRegressor(max_iter=500)\n",
    "\n",
    "sgd.fit(x_train,y_train.ravel())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "使用SGDRegressor模型进行500轮训练</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:29:55.295978Z",
     "start_time": "2021-11-13T07:29:55.280916Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "参数w:\n",
      " [0.73513783] [-0.00178178] \n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(\"参数w:\\n\",sgd.coef_,sgd.intercept_,\"\\n\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "$得到公式为y=wx+b$\n",
    "其中w=[0.73416399] \n",
    "b = [-0.00038272] </div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:33:44.963708Z",
     "start_time": "2021-11-13T07:33:44.948749Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的销售额(标准化):\n",
      " [ 0.85297763 -0.28028488 -0.92477498 -0.7399124   1.10829864]\n"
     ]
    }
   ],
   "source": [
    "# 预测房子价格(标准值)\n",
    "y_predict = sgd.predict(x_test)\n",
    "print(\"预测的销售额(标准化):\\n\",y_predict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "上述为2021年的<span class=\"burk\">销售额</span>预测结果(标准化后)</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-13T07:33:51.441478Z",
     "start_time": "2021-11-13T07:33:51.424500Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的销售额为:\n",
      " [12672.48189756  7777.34516818  4993.46488136  5791.98032302\n",
      " 13775.34309191]\n"
     ]
    }
   ],
   "source": [
    "# 预测房子的价格(正常值)\n",
    "value_predict = std_y.inverse_transform(y_predict)\n",
    "\n",
    "print(\"预测的销售额为:\\n\",value_predict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"mark\">\n",
    "上述为2021年的<span class=\"burk\">销售额</span>预测结果(标准化逆变化后)</div><i class=\"fa fa-lightbulb-o \"></i>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}